package selenium.other;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

/**
 * @Author quan
 * @Description 显式等待：我也没看懂这段代码说明了什么？
 * @Date 2023/5/18 10:51
 */
public class Demo1_ObviousWait {
    public static void main(String[] args) throws InterruptedException {
        //显式等待：等待的是条件满足即可
        obviousWait();
        //隐式等待：等待的是页面上所有的元素
//        hideWait();
    }

    private static void hideWait() throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("http://localhost:63342/TestClass/src/main/Page/test02.html?_ijt=i9kkvfm96mgth3dd3t6grsb9pv&_ij_reload=RELOAD_ON_SAVE");
        sleep(3000);
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    }

    private static void obviousWait() throws InterruptedException {
        //创建驱动
        WebDriver webDriver = new ChromeDriver();
        //test02的页面
        webDriver.get("http://localhost:63342/TestClass/src/main/Page/test02.html?_ijt=i9kkvfm96mgth3dd3t6grsb9pv&_ij_reload=RELOAD_ON_SAVE");
        sleep(3000);
        WebDriverWait wait = new WebDriverWait(webDriver,50);
        wait.until(ExpectedConditions.textToBe(By.cssSelector("h3"),"frame"));
    }
}
